<?php
header("Access-Control-Allow-Origin:*");
require("../lib/init.php");
require("../pojo/token.php");
require("../pojo/admin.php");
$id = $_POST["id"];
$username = $_POST['username'];
$token = $_POST['token'];
if (empty($id) or empty($username) or empty($token)) exit("缺少必要参数");
if (!checkToken($token)) {
    $code = 400;
    $msg ="没有权限";
} else {
    if (!checkAdmin($username)) {
        $sql = "update admin set username='$username' where id='$id'";
        if (!MQuery($sql)) {
            $code = 400;
            $msg = "修改信息失败！";
        } else {
            $code = 200;
            $msg = "修改信息成功！";
        }
    }else{
        $code = 400;
        $msg = "对不起，角色已经存在！";
    }
}

echo json_encode(resultmsg($code, $msg));
